/*********************************************************************************
 *      Copyright:  (C) 2017 luminqi
 *                  All rights reserved.
 *
 *       Filename:  sq_search.c
 *    Description:  This file 
 *                 
 *        Version:  1.0.0(2017年08月26日)
 *         Author:  luminqi <958822582@qq.com>
 *      ChangeLog:  1, Release initial version on "2017年08月26日 15时38分39秒"
 *                 
 ********************************************************************************/

#include <stdio.h>

int sq_search(int array[], int length, int key);
int main(int argc, char **argv)
{
    int n = 0;
    int i = 0;
    int a[n];
    int res = 0;
    int key = 0;
    
    printf("the array has n number:");
    scanf("%d",&n);

    printf("please input n number:\n");
    for (i = 0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    
    printf("please input a key:");
    scanf("%d",&key);

    res = sq_search(a, n, key);
    if(res == -1)
    {
        printf("not found!");
    }
    else
    {
        printf("the index of %d is array[%d]\n",key,res);
    }
    return 0;
}

int sq_search(int array[], int length, int key)
{
    int i = 0;
    for (i=0; i<length; i++)
    {
        if(array[i]==key)
        {
            return i;
        }
    }
    return -1;
}
